package com.mmm.order.mq;

import com.sun.org.apache.regexp.internal.RE;
import org.springframework.amqp.core.Binding;
import org.springframework.amqp.core.BindingBuilder;
import org.springframework.amqp.core.Queue;
import org.springframework.amqp.core.TopicExchange;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

import static com.mmm.order.variable.ExpressMQVaribale.*;

/**
 * @email 1067559930@qq.com
 * @author: One
 * @date: 2022/03/09
 * @time: 16:28
 */
@Configuration
public class MqConfig {

    @Bean
    public TopicExchange topicExchange() {
        return new TopicExchange(EXPRESS_EXCHANGE, true, false);
    }

    @Bean
    public Queue insertQueue() {
        return new Queue(EXPRESS_INSERT_QUEUE, true);
    }

    @Bean
    public Queue deleteQueue(){
        return new Queue(EXPRESS_DELETE_QUEUE,true);
    }

    @Bean
    public Binding insertQueueBinding(){
        return BindingBuilder.bind(insertQueue())
                .to(topicExchange())
                .with(EXPRESS_INSERT_KEY);
    }

    @Bean
    public Binding deleteQueueBinding(){
        return BindingBuilder.bind(deleteQueue())
                .to(topicExchange())
                .with(EXPRESS_DELETE_KEY);
    }
}
